# -*- coding: utf-8 -*-
from django.db import models

# Create your models here.
class domain_model(models.Model):
    name =  models.CharField('模板名称', max_length=100, unique=True)
    context =  models.TextField('模板内容', blank=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = '模板名称'
        verbose_name_plural = '模板名称'
        ordering = ['name']  # 按照哪个栏目排序

class source_type(models.Model):
    name =  models.CharField('回源方式', max_length=100, unique=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = '回源方式'
        verbose_name_plural = '回源方式'
        ordering = ['name']  # 按照哪个栏目排序


class source_line(models.Model):
    name =  models.CharField('源站线路', max_length=100, unique=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = '源站线路'
        verbose_name_plural = '源站线路'
        ordering = ['name']  # 按照哪个栏目排序


class source_line_record(models.Model):
    source_ip =  models.CharField('回源方式', max_length=100, unique=True)
    source_port =  models.CharField('回源方式', max_length=100, unique=True)
    source_type =  models.CharField('回源方式', max_length=100, unique=True)
    source_weight =  models.CharField('回源方式', max_length=100, unique=True)
    max_fail =  models.CharField('回源方式', max_length=100, unique=True)
    silence_time =  models.CharField('回源方式', max_length=100, unique=True)
    source_line =  models.ForeignKey(source_line)
    domain_name =  models.CharField('回源方式', max_length=100, unique=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = '源站线路'
        verbose_name_plural = '源站线路'
        ordering = ['source_line']  # 按照哪个栏目排序


class domain_info(models.Model):
    user_id = models.CharField('user id', max_length=100, blank=True)
    project_name = models.CharField('名称', max_length=100)
    domain_name = models.CharField('域名', max_length=100)
    source_ip = models.CharField( '源站IP', max_length=100)
    source_port = models.IntegerField( '源站端口', default=80)
    last_update_time = models.CharField( '源站IP', max_length=100, blank=True)
    dnspod = models.IntegerField( 'dnspod', default=1) #是否可以通过dnspod操作,是的话存域名ID，不能的话NULL
    cname_domain = models.CharField( 'cname_domain', max_length=100, blank=True)
    cname_ip = models.CharField( 'cname_ip', max_length=100, blank=True)
    token  = models.CharField( 'token', max_length=100, blank=True)
    status = models.CharField( 'status', max_length=100, blank=True) #('cname','invalid','a') NOT NULL DEFAULT 'invalid',
    a_ip = models.CharField( 'a_ip', max_length=100, blank=True)
    model =  models.ForeignKey(domain_model)
    #回源host
    source_type = models.ForeignKey(source_type,default='HTTP协议回源')#回源方式
    source_line = models.ForeignKey(source_line,default='电信')#源站线路
    #新建一张表，测试？


    def __unicode__(self):
        return self.domain_name

    class Meta:
        verbose_name = '域名'
        verbose_name_plural = '域名'
        ordering = ['source_ip']  # 按照哪个栏目排序

